package ${package.Entity};

<#list table.importPackages as pkg>
import ${pkg};
</#list>
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
<#if entityLombokModel>
import lombok.Data;
import lombok.EqualsAndHashCode;
    <#if chainModel>
import lombok.experimental.Accessors;
    </#if>
</#if>
import com.baomidou.mybatisplus.annotation.IdType;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.ColumnType;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;


/**
 * @author: ${author}
 * @date: ${date}
 * @description: ${table.comment!}
 */
<#if entityLombokModel>
@Data
    <#if superEntityClass??>
@EqualsAndHashCode(callSuper = true)
    <#else>
@EqualsAndHashCode(callSuper = false)
    </#if>
    <#if chainModel>
@Accessors(chain = true)
    </#if>
</#if>
<#if table.convert>
@TableName("${table.name}")
</#if>
@ApiModel(value="${entity}对象", description="${table.comment!}")
<#if superEntityClass??>
public class ${entity} extends ${superEntityClass}<#if activeRecord><${entity}></#if> {
<#elseif activeRecord>
public class ${entity} extends Model<${entity}> {
<#else>
public class ${entity} implements Serializable {
</#if>

<#if entitySerialVersionUID>
    private static final long serialVersionUID = 1L;
</#if>
<#-- ----------  BEGIN 字段循环遍历  ---------->
<#list table.fields as field>
    <#if field.keyFlag>
        <#assign keyPropertyName="${field.propertyName}"/>
    </#if>

    <#if field.comment!?length gt 0>
    @ApiModelProperty(value = "${field.comment}")
<#--    @ApiModelProperty(value = "${field.metaInfo}")-->
    </#if>
    <#if field.keyFlag>
    <#-- 主键 -->
        <#if field.keyIdentityFlag>
    @TableId(value = "${field.annotationColumnName}", type = IdType.AUTO)
        <#elseif idType??>
    @TableId(value = "${field.annotationColumnName}", type = IdType.${idType})
        <#elseif field.convert>
    @TableId(value = "${field.annotationColumnName}", type = IdType.ASSIGN_UUID)
    @Column(name = "guid", type = MySqlTypeConstant.VARCHAR, isKey = true, length = 36, isNull = false, comment = "主键")
        </#if>
    <#-- 普通字段 -->
    <#elseif field.fill??>
    <#-- -----   存在字段填充设置   ----->
        <#if field.convert>
    @TableField(value = "${field.annotationColumnName}", fill = FieldFill.${field.fill})
        <#else>
    @TableField(fill = FieldFill.${field.fill})
        </#if>
    <#elseif field.convert>
    @TableField("${field.annotationColumnName}")
    </#if>
    <#if !field.keyFlag>
        <#if field.metaInfo.jdbcType == "VARCHAR">
    @ColumnType(value = MySqlTypeConstant.VARCHAR, length = ${field.metaInfo.length?string('#')})
        <#elseif field.metaInfo.jdbcType == "LONGVARCHAR">
    @ColumnType(value = MySqlTypeConstant.TEXT)
        <#elseif field.metaInfo.jdbcType == "DECIMAL">
    @ColumnType(value = MySqlTypeConstant.DECIMAL, length = ${field.metaInfo.length}, decimalLength = 2)
        <#elseif field.metaInfo.jdbcType == "TIMESTAMP">
    @ColumnType(value = MySqlTypeConstant.DATETIME)
        <#elseif field.metaInfo.jdbcType == "DATE">
    @ColumnType(value = MySqlTypeConstant.DATE)
        <#elseif field.metaInfo.jdbcType == "INTEGER">
    @ColumnType(value = MySqlTypeConstant.INT, length = ${field.metaInfo.length})
        <#elseif field.metaInfo.jdbcType == "BIT">
    @ColumnType(value = MySqlTypeConstant.TINYINT, length = ${field.metaInfo.length})
        <#else>
    @ColumnType(value = MySqlTypeConstant.VARCHAR, length = ${field.metaInfo.length})
        </#if>
        <#if field.metaInfo.defaultValue??>
    @Column(name = "${field.annotationColumnName}", comment = "${field.comment}", defaultValue = "${field.metaInfo.defaultValue}")
        <#else>
    @Column(name = "${field.annotationColumnName}", comment = "${field.comment}")
        </#if>
    </#if>
<#-- 乐观锁注解 -->
    <#if (versionFieldName!"") == field.name>
    @Version
    </#if>
<#-- 逻辑删除注解 -->
    <#if (logicDeleteFieldName!"") == field.name>
    @TableLogic
    @JsonIgnore
    </#if>
    <#if field.propertyType == "LocalDateTime" || field.name == "createBy" || field.name == "updateBy">
    @JsonIgnore
    </#if>
    private ${field.propertyType} ${field.propertyName};
</#list>
<#------------  END 字段循环遍历  ---------->

<#if !entityLombokModel>
    <#list table.fields as field>
        <#if field.propertyType == "boolean">
            <#assign getprefix="is"/>
        <#else>
            <#assign getprefix="get"/>
        </#if>
        public ${field.propertyType} ${getprefix}${field.capitalName}() {
        return ${field.propertyName};
        }

        <#if chainModel>
            public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
        <#else>
            public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
        </#if>
        this.${field.propertyName} = ${field.propertyName};
        <#if chainModel>
            return this;
        </#if>
        }
    </#list>
</#if>

<#if entityColumnConstant>
    <#list table.fields as field>
        public static final String ${field.name?upper_case} = "${field.name}";

    </#list>
</#if>
<#if activeRecord>
    @Override
    protected Serializable pkVal() {
    <#if keyPropertyName??>
        return this.${keyPropertyName};
    <#else>
        return null;
    </#if>
    }

</#if>
<#if !entityLombokModel>
    @Override
    public String toString() {
    return "${entity}{" +
    <#list table.fields as field>
        <#if field_index==0>
            "${field.propertyName}=" + ${field.propertyName} +
        <#else>
            ", ${field.propertyName}=" + ${field.propertyName} +
        </#if>
    </#list>
    "}";
    }
</#if>
}